package com.demo.controller;

import com.demo.common.R;
import com.demo.domain.SetmealDish;
import com.demo.domain.ShoppingCart;
import com.demo.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shoppingCart")
@Slf4j
@Api(tags="购物车详情")
public class ShoppingCartConrolller {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 查询购物车信息
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询购物车信息")
    public R<List<ShoppingCart>> cartListApi(){
        return shoppingCartService.cartListApi();
    }


    /**
     * 添加商品至购物车
     * @param shoppingCart
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加商品至购物车")
    public R<ShoppingCart> addCartApi(@RequestBody ShoppingCart shoppingCart){
        log.info("前端传来的参数shoppingCart为 {}",shoppingCart.toString() );
        return shoppingCartService.addCartApi(shoppingCart);
    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    @ApiOperation(value = "清空购物车")
    public R<String> clean(){
        return shoppingCartService.clean();
    }


    /**
     * 修改购物车商品数量
     * @param shoppingCart
     * @return
     */
    @PostMapping("/sub")
    @ApiOperation(value = "修改购物车商品数量")
    public R<String> sub(@RequestBody ShoppingCart shoppingCart){
        log.info("前端传来的shoppingCart为 {}",shoppingCart);
        return shoppingCartService.sub(shoppingCart);
    }
}
